<!DOCTYPE HTML>
<html>

<head>
	<link rel="bookmark"  type="image/x-icon"  href="/img/logo_miccall.png"/>
	<link rel="shortcut icon" href="/img/logo_miccall.png">
	
			    <title>
    Ame雨
    </title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
    <link rel="stylesheet" href="/amelin-ting/css/mic_main.css" />
    <link rel="stylesheet" href="/amelin-ting/css/dropdownMenu.css" />
    <meta name="keywords" content="Ame雨" />
    
    	<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
	 
    <noscript>
        <link rel="stylesheet" href="/amelin-ting/css/noscript.css" />
    </noscript>
    <style type="text/css">
        body:before {
          content: ' ';
          position: fixed;
          top: 0;
          background: url('/amelin-ting/img/bg.jpg') center 0 no-repeat;
          right: 0;
          bottom: 0;
          left: 0;
          background-size: cover; 
        }
    </style>

			    
  
    <script type="text/x-mathjax-config">
      MathJax.Hub.Config({
        tex2jax: {
          inlineMath: [ ['$','$'], ["\\(","\\)"]  ],
          processEscapes: true,
          skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
        }
      });
    </script>

    <script type="text/x-mathjax-config">
      MathJax.Hub.Queue(function() {
        var all = MathJax.Hub.getAllJax(), i;
        for (i=0; i < all.length; i += 1) {
          all[i].SourceElement().parentNode.className += ' has-jax';
        }
      });
    </script>
    <script async type="text/javascript" src="//cdn.bootcss.com/mathjax/2.7.1/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
  


    <script src="/amelin-ting/js/jquery.min.js"></script>
    <script src="/amelin-ting/js/jquery.scrollex.min.js"></script>
    <script src="/amelin-ting/js/jquery.scrolly.min.js"></script>
    <script src="/amelin-ting/js/skel.min.js"></script>
    <script src="/amelin-ting/js/util.js"></script>
    <script src="/amelin-ting/js/main.js"></script>
	
<meta name="generator" content="Hexo 5.4.0"></head>
    
		
<!-- Layouts -->



<!--  代码渲染  -->
<link rel="stylesheet" href="/css/prism_coy.css" />
<link rel="stylesheet" href="/css/typo.css" />
<!-- 文章页 -->
<body class="is-loading">
    <!-- Wrapper 外包 s-->
    <div id="wrapper" class="fade-in">
        <!-- Intro 头部显示 s -->
        <!-- Intro 头部显示 e -->
        <!-- Header 头部logo start -->
        <header id="header">
    <a href="/amelin-ting/" class="logo">Art Space</a>
</header>
        <!-- Nav 导航条 start -->
        <nav id="nav" class="special" >
            <ul class="menu links" >
			<!-- Homepage  主页  --> 
			<li >
	            <a href="/amelin-ting/" rel="nofollow">主页</a>
	        </li>
			<!-- categories_name  分类   --> 
	        
	        <li class="active">
	            <a href="#s1">分类</a>
	                    <ul class="submenu">
	                        <li>
	                        <a class="category-link" href="/amelin-ting/categories/Go/">Go</a></li><li><a class="category-link" href="/amelin-ting/categories/django/">django</a></li><li><a class="category-link" href="/amelin-ting/categories/drf/">drf</a></li><li><a class="category-link" href="/amelin-ting/categories/gin/">gin</a></li><li><a class="category-link" href="/amelin-ting/categories/go/">go</a></li><li><a class="category-link" href="/amelin-ting/categories/linux/">linux</a></li><li><a class="category-link" href="/amelin-ting/categories/mysql/">mysql</a></li><li><a class="category-link" href="/amelin-ting/categories/python/">python</a></li><li><a class="category-link" href="/amelin-ting/categories/%E5%86%85%E7%BD%91%E7%A9%BF%E9%80%8F/">内网穿透</a></li><li><a class="category-link" href="/amelin-ting/categories/%E5%89%8D%E7%AB%AF/">前端</a>
	                    </ul>
	        </li>
	        
	        <!-- archives  归档   --> 
	        
	        
		        <!-- Pages 自定义   -->
		        
		        <li>
		            <a href="/about/" title="简历">
		                简历
		            </a>
		        </li>
		        
		        <li>
		            <a href="/group/" title="团队">
		                团队
		            </a>
		        </li>
		        
		        <li>
		            <a href="/gallery/" title="图库">
		                图库
		            </a>
		        </li>
		        
		        <li>
		            <a href="/tag/" title="标签">
		                标签
		            </a>
		        </li>
		        


            </ul>
            <!-- icons 图标   -->
			<ul class="icons">
                    
                    <li>
                        <a title="github" href="https://github.com/miccall" target="_blank" rel="noopener">
                            <i class="icon fa fa-github"></i>
                        </a>
                    </li>
                    
                    <li>
                        <a title="500px" href="http://500px.com" target="_blank" rel="noopener">
                            <i class="icon fa fa-500px"></i>
                        </a>
                    </li>
                    
			</ul>
</nav>

        <div id="main" >
            <div class ="post_page_title_img" style="height: 25rem;background-image: url(https://img0.baidu.com/it/u=3687797924,1850770882&amp;fm=253&amp;fmt=auto&amp;app=138&amp;f=PNG?w=500&amp;h=281);background-position: center; background-repeat:no-repeat; background-size:cover;-moz-background-size:cover;overflow:hidden;" >
                <a href="#" style="padding: 4rem 4rem 2rem 4rem ;"><h2 >Go Map</h2></a>
            </div>
            <!-- Post -->
            <div class="typo" style="padding: 3rem;">
                <h2 id="一、map"><a href="#一、map" class="headerlink" title="一、map"></a>一、map</h2><figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br></pre></td><td class="code"><pre><span class="line">	<span class="keyword">map</span>是一种无序的基于key:value的数据结构，Go语言中的<span class="keyword">map</span>是引用类型，必须初始化才能使用</span><br><span class="line"></span><br><span class="line"><span class="number">1.</span> <span class="keyword">map</span>类型是一个key:value的数据结构</span><br><span class="line">        <span class="keyword">var</span> a <span class="keyword">map</span>[key类型]value类型</span><br><span class="line">            <span class="keyword">var</span> a <span class="keyword">map</span>[<span class="keyword">string</span>]<span class="keyword">int</span> </span><br><span class="line">            <span class="keyword">var</span> b <span class="keyword">map</span>[<span class="keyword">int</span>]<span class="keyword">string</span></span><br><span class="line">        <span class="comment">// map必须初始化才能使用，否则panic</span></span><br><span class="line"></span><br><span class="line"><span class="number">2.</span> <span class="keyword">map</span>类型的变量默认初始化为<span class="literal">nil</span>，需要使用<span class="built_in">make</span>分配<span class="keyword">map</span>内存</span><br><span class="line">        <span class="keyword">package</span> main</span><br><span class="line"></span><br><span class="line">        <span class="keyword">import</span> (</span><br><span class="line">            <span class="string">&quot;fmt&quot;</span></span><br><span class="line">        )</span><br><span class="line"></span><br><span class="line">        <span class="function"><span class="keyword">func</span> <span class="title">main</span><span class="params">()</span></span> &#123;</span><br><span class="line">            <span class="keyword">var</span> a <span class="keyword">map</span>[<span class="keyword">string</span>]<span class="keyword">int</span></span><br><span class="line">            <span class="keyword">if</span> a == <span class="literal">nil</span> &#123;</span><br><span class="line">                fmt.Println(<span class="string">&quot;null&quot;</span>)</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line"><span class="number">3.</span> <span class="keyword">map</span>插入操作</span><br><span class="line">        <span class="keyword">package</span> main</span><br><span class="line"></span><br><span class="line">        <span class="keyword">import</span> (</span><br><span class="line">            <span class="string">&quot;fmt&quot;</span></span><br><span class="line">        )</span><br><span class="line"></span><br><span class="line">        <span class="function"><span class="keyword">func</span> <span class="title">main</span><span class="params">()</span></span> &#123;</span><br><span class="line">            <span class="keyword">var</span> a <span class="keyword">map</span>[<span class="keyword">string</span>]<span class="keyword">int</span></span><br><span class="line">            <span class="keyword">if</span> a == <span class="literal">nil</span> &#123;</span><br><span class="line">                s := <span class="built_in">make</span>(<span class="keyword">map</span>[<span class="keyword">string</span>]<span class="keyword">int</span>)</span><br><span class="line">                s[<span class="string">&quot;age&quot;</span>] = <span class="number">1</span></span><br><span class="line">                s[<span class="string">&quot;salary&quot;</span>] = <span class="number">20000</span></span><br><span class="line">                fmt.Println(s)</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line"><span class="number">4.</span> 通过key来查看<span class="keyword">map</span>中的元素</span><br><span class="line">    <span class="number">4.1</span></span><br><span class="line">        <span class="function"><span class="keyword">func</span> <span class="title">main</span><span class="params">()</span></span> &#123;</span><br><span class="line">            s := <span class="keyword">map</span>[<span class="keyword">string</span>]<span class="keyword">int</span>&#123;</span><br><span class="line">                <span class="string">&quot;age&quot;</span>:    <span class="number">1</span>,</span><br><span class="line">                <span class="string">&quot;salary&quot;</span>: <span class="number">20000</span>,</span><br><span class="line">            &#125;</span><br><span class="line">            fmt.Println(s[<span class="string">&quot;age&quot;</span>])</span><br><span class="line">        &#125;</span><br><span class="line">	</span><br><span class="line">	<span class="number">4.2</span> </span><br><span class="line">        <span class="function"><span class="keyword">func</span> <span class="title">main</span><span class="params">()</span></span> &#123;</span><br><span class="line">            a := <span class="keyword">map</span>[<span class="keyword">string</span>]<span class="keyword">int</span>&#123;<span class="string">&quot;steve&quot;</span>: <span class="number">12000</span>, <span class="string">&quot;jamie&quot;</span>: <span class="number">15000</span>&#125;</span><br><span class="line">            a[<span class="string">&quot;mike&quot;</span>] = <span class="number">9000</span></span><br><span class="line">            b := <span class="string">&quot;jamie&quot;</span></span><br><span class="line">            fmt.Println(a[b])</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line"><span class="number">5.</span> 如何判断<span class="keyword">map</span>中指定的key是否存在?</span><br><span class="line">	value, is_exist := <span class="keyword">map</span>[key]</span><br><span class="line">		<span class="function"><span class="keyword">func</span> <span class="title">main</span><span class="params">()</span></span> &#123;</span><br><span class="line">            s := <span class="keyword">map</span>[<span class="keyword">string</span>]<span class="keyword">int</span>&#123;</span><br><span class="line">                <span class="string">&quot;age&quot;</span>: <span class="number">1</span>,</span><br><span class="line">                <span class="string">&quot;salary&quot;</span>: <span class="number">20000</span>,</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="comment">// a := &quot;kidding&quot;</span></span><br><span class="line">            <span class="comment">// value, is_exist := s[a]</span></span><br><span class="line">            value, is_exist := s[<span class="string">&quot;kidding&quot;</span>]</span><br><span class="line">            <span class="keyword">if</span> is_exist == <span class="literal">true</span> &#123;</span><br><span class="line">                fmt.Println(<span class="string">&quot;True&quot;</span>)</span><br><span class="line">                fmt.Print(value)</span><br><span class="line">            &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">                fmt.Println(<span class="string">&quot;False&quot;</span>)</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line"><span class="number">6.</span> <span class="keyword">map</span>遍历操作</span><br><span class="line">        <span class="function"><span class="keyword">func</span> <span class="title">main</span><span class="params">()</span></span> &#123;</span><br><span class="line">            s := <span class="keyword">map</span>[<span class="keyword">string</span>]<span class="keyword">int</span>&#123;</span><br><span class="line">                <span class="string">&quot;age&quot;</span>:    <span class="number">1</span>,</span><br><span class="line">                <span class="string">&quot;salary&quot;</span>: <span class="number">20000</span>,</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">for</span> key, value := <span class="keyword">range</span> s &#123;</span><br><span class="line">                fmt.Printf(<span class="string">&quot;key: %s value: %d\n&quot;</span>, key, value)</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line"><span class="number">7.</span> <span class="keyword">map</span>删除元素</span><br><span class="line">        <span class="function"><span class="keyword">func</span> <span class="title">main</span><span class="params">()</span></span> &#123;</span><br><span class="line">            s := <span class="keyword">map</span>[<span class="keyword">string</span>]<span class="keyword">int</span>&#123;</span><br><span class="line">                <span class="string">&quot;age&quot;</span>:    <span class="number">1</span>,</span><br><span class="line">                <span class="string">&quot;salary&quot;</span>: <span class="number">20000</span>,</span><br><span class="line">            &#125;</span><br><span class="line">            fmt.Println(s)</span><br><span class="line">            <span class="built_in">delete</span>(s, <span class="string">&quot;age&quot;</span>)</span><br><span class="line">            fmt.Println(s)</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line"><span class="number">8.</span> <span class="keyword">map</span>是引用类型</span><br><span class="line">        <span class="function"><span class="keyword">func</span> <span class="title">main</span><span class="params">()</span></span> &#123;</span><br><span class="line">            s := <span class="keyword">map</span>[<span class="keyword">string</span>]<span class="keyword">int</span>&#123;</span><br><span class="line">                <span class="string">&quot;age&quot;</span>:    <span class="number">1</span>,</span><br><span class="line">                <span class="string">&quot;salary&quot;</span>: <span class="number">20000</span>,</span><br><span class="line">            &#125;</span><br><span class="line">            b := s</span><br><span class="line">            fmt.Printf(<span class="string">&quot;s(%v, addr:%p\n)&quot;</span>, s, s)</span><br><span class="line">            fmt.Printf(<span class="string">&quot;b(%v, addr:%p\n)&quot;</span>, b, b)</span><br><span class="line">            b[<span class="string">&quot;age&quot;</span>] = <span class="number">2</span></span><br><span class="line">            fmt.Printf(<span class="string">&quot;s(%v, addr:%p\n)&quot;</span>, s, s)</span><br><span class="line">            fmt.Printf(<span class="string">&quot;b(%v, addr:%p\n)&quot;</span>, b, b)</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="comment">/*</span></span><br><span class="line"><span class="comment">        s(map[age:1 salary:20000], addr:0xc000078480)</span></span><br><span class="line"><span class="comment">        b(map[age:1 salary:20000], addr:0xc000078480)</span></span><br><span class="line"><span class="comment">        s(map[age:2 salary:20000], addr:0xc000078480)</span></span><br><span class="line"><span class="comment">        b(map[age:2 salary:20000], addr:0xc000078480)</span></span><br><span class="line"><span class="comment">        所以跟数组不同，重新赋值给b，b修改，a也随之修改</span></span><br><span class="line"><span class="comment">        */</span></span><br><span class="line"></span><br><span class="line"><span class="number">9.</span> 默认情况下，<span class="keyword">map</span>并不是按照key有序进行遍历的</span><br><span class="line"></span><br><span class="line"><span class="number">10.</span> <span class="keyword">map</span>按照key进行排序</span><br><span class="line">        <span class="keyword">package</span> main</span><br><span class="line"></span><br><span class="line">        <span class="keyword">import</span> (</span><br><span class="line">            <span class="string">&quot;fmt&quot;</span></span><br><span class="line">            <span class="string">&quot;sort&quot;</span></span><br><span class="line">        )</span><br><span class="line"></span><br><span class="line">        <span class="function"><span class="keyword">func</span> <span class="title">main</span><span class="params">()</span></span> &#123;</span><br><span class="line">            <span class="keyword">var</span> a <span class="keyword">map</span>[<span class="keyword">string</span>]<span class="keyword">int</span> = <span class="built_in">make</span>(<span class="keyword">map</span>[<span class="keyword">string</span>]<span class="keyword">int</span>, <span class="number">10</span>)</span><br><span class="line">            <span class="keyword">for</span> i := <span class="number">0</span>; i &lt; <span class="number">10</span>; i++ &#123;</span><br><span class="line">                key := fmt.Sprintf(<span class="string">&quot;key%d&quot;</span>, i)</span><br><span class="line">                a[key] = i</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">var</span> keys []<span class="keyword">string</span></span><br><span class="line">            <span class="keyword">for</span> key, _ := <span class="keyword">range</span> a &#123;</span><br><span class="line">                keys = <span class="built_in">append</span>(keys, key)</span><br><span class="line">            &#125;</span><br><span class="line">            sort.Strings(keys)</span><br><span class="line">            <span class="keyword">for</span> _, key := <span class="keyword">range</span> keys &#123;</span><br><span class="line">                fmt.Printf(<span class="string">&quot;key:%s=%d\n&quot;</span>, key, a[key])</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line"><span class="number">11.</span> <span class="keyword">map</span>的切片</span><br><span class="line">        <span class="function"><span class="keyword">func</span> <span class="title">main</span><span class="params">()</span></span> &#123;</span><br><span class="line">            <span class="keyword">var</span> mapSlice []<span class="keyword">map</span>[<span class="keyword">string</span>]<span class="keyword">int</span></span><br><span class="line">            mapSlice = <span class="built_in">make</span>([]<span class="keyword">map</span>[<span class="keyword">string</span>]<span class="keyword">int</span>, <span class="number">5</span>)</span><br><span class="line">            fmt.Println(<span class="string">&quot;before map init&quot;</span>)</span><br><span class="line">            <span class="keyword">for</span> index, value := <span class="keyword">range</span> mapSlice &#123;</span><br><span class="line">                fmt.Printf(<span class="string">&quot;index:%d value:%v\n&quot;</span>, index, value)</span><br><span class="line">            &#125;</span><br><span class="line">            fmt.Println()</span><br><span class="line">            mapSlice[<span class="number">0</span>] = <span class="built_in">make</span>(<span class="keyword">map</span>[<span class="keyword">string</span>]<span class="keyword">int</span>, <span class="number">10</span>)</span><br><span class="line">            mapSlice[<span class="number">0</span>][<span class="string">&quot;a&quot;</span>] = <span class="number">1000</span></span><br><span class="line">            mapSlice[<span class="number">0</span>][<span class="string">&quot;b&quot;</span>] = <span class="number">2000</span></span><br><span class="line">            mapSlice[<span class="number">0</span>][<span class="string">&quot;c&quot;</span>] = <span class="number">3000</span></span><br><span class="line">            mapSlice[<span class="number">0</span>][<span class="string">&quot;d&quot;</span>] = <span class="number">4000</span></span><br><span class="line">            mapSlice[<span class="number">0</span>][<span class="string">&quot;e&quot;</span>] = <span class="number">5000</span></span><br><span class="line">            fmt.Println(<span class="string">&quot;after map init&quot;</span>)</span><br><span class="line">            <span class="keyword">for</span> index, value := <span class="keyword">range</span> mapSlice &#123;</span><br><span class="line">                fmt.Printf(<span class="string">&quot;index:%d value:%v\n&quot;</span>, index, value)</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="课后小作业"><a href="#课后小作业" class="headerlink" title="课后小作业"></a>课后小作业</h2><figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span> 写一个程序，统计一个字符串中每个单词出现的次数。比如：”how do you do”中how=<span class="number">1</span> do=<span class="number">2</span> you=<span class="number">1</span>。</span><br><span class="line">    	<span class="keyword">package</span> main</span><br><span class="line"></span><br><span class="line">        <span class="keyword">import</span> (</span><br><span class="line">            <span class="string">&quot;fmt&quot;</span></span><br><span class="line">            <span class="string">&quot;strings&quot;</span></span><br><span class="line">        )</span><br><span class="line"></span><br><span class="line">        <span class="function"><span class="keyword">func</span> <span class="title">main</span><span class="params">()</span></span> &#123;</span><br><span class="line">            <span class="comment">// 定义新字符串</span></span><br><span class="line">            <span class="keyword">var</span> str <span class="keyword">string</span> = <span class="string">&quot;how do you do&quot;</span></span><br><span class="line">            <span class="comment">// 对字符串进行切割</span></span><br><span class="line">            newArrey := strings.Split(str, <span class="string">&quot; &quot;</span>)</span><br><span class="line">            <span class="comment">// 定义次数</span></span><br><span class="line">            countMap := <span class="built_in">make</span>(<span class="keyword">map</span>[<span class="keyword">string</span>]<span class="keyword">int</span>, <span class="number">10</span>)</span><br><span class="line">            <span class="comment">// 循环出</span></span><br><span class="line">            <span class="keyword">for</span> _, key := <span class="keyword">range</span> newArrey &#123;</span><br><span class="line">                _, isReal := countMap[key]</span><br><span class="line">                <span class="keyword">if</span> !isReal &#123;</span><br><span class="line">                    countMap[key] = <span class="number">1</span></span><br><span class="line">                &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">                    countMap[key] += <span class="number">1</span></span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">            fmt.Println(countMap)</span><br><span class="line">        &#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>


            </div>

            <!-- Post Comments -->
            
    <!-- 使用 DISQUS_CLICK -->
<div id="disqus-comment">
    <div id="disqus_thread"></div>

<!-- add animation -->
<style>
	.disqus_click_btn {
            line-height: 30px;
            margin: 0;
            min-width: 50px;
            padding: 0 14px;
            display: inline-block;
            font-family: "Roboto", "Helvetica", "Arial", sans-serif;
            font-size: 14px;
            font-weight: 400;
            text-transform: uppercase;
            letter-spacing: 0;
            overflow: hidden;
            will-change: box-shadow;
            transition: box-shadow .2s cubic-bezier(.4, 0, 1, 1), background-color .2s cubic-bezier(.4, 0, .2, 1), color .2s cubic-bezier(.4, 0, .2, 1);
            outline: 0;
            cursor: pointer;
            text-decoration: none;
            text-align: center;
            vertical-align: middle;
            border: 0;
            background: rgba(158, 158, 158, .2);
            box-shadow: 0 2px 2px 0 rgba(0, 0, 0, .14), 0 3px 1px -2px rgba(0, 0, 0, .2), 0 1px 5px 0 rgba(0, 0, 0, .12);
            color: #fff;
            background-color: #7EC0EE;
            text-shadow: 0
        }
</style>
	
<div class="btn_click_load" id="disqus_bt"> 
    <button class="disqus_click_btn">点击查看评论</button>
</div>

<!--
<script type="text/javascript">
$('.btn_click_load').click(function() {
    /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
    var disqus_shortname = 'http-miccall-tech'; // required: replace example with your forum shortname

    /* * * DON'T EDIT BELOW THIS LINE * * */
    (function() {
      var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
      dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
      (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
    })();

    document.getElementById('disqus_bt').style.display = "none";
});
</script>
-->
<script type="text/javascript">
    var disqus_config = function () {
        this.page.url = 'https://gitee.com/AmeX/amelin-ting.git/2020/03/04/Go%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B------map/';  // Replace PAGE_URL with your page's canonical URL variable
        this.page.identifier = 'https://gitee.com/AmeX/amelin-ting.git/2020/03/04/Go%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B------map/'; // Replace PAGE_IDENTIFIER with your page's unique identifier variable
    };
</script>

<script type="text/javascript">
    $('.btn_click_load').click(function() {  //click to load comments
        (function() { // DON'T EDIT BELOW THIS LINE
            var d = document;
            var s = d.createElement('script');
            s.src = '//http-miccall-tech.disqus.com/embed.js';
            s.setAttribute('data-timestamp', + new Date());
            (d.head || d.body).appendChild(s);
        })();
        $('.btn_click_load').css('display','none');
    });
</script>
</div>
<style>
    #disqus-comment{
        background-color: #eee;
        padding: 2pc;
    }
</style>


        </div>
        <!-- Copyright 版权 start -->
                <div id="copyright">
            <ul>
                <li>&copy;Powered By <a target="_blank" rel="noopener" href="https://hexo.io/zh-cn/" style="border-bottom: none;">hexo</a></li>
                <li>Design: <a target="_blank" rel="noopener" href="http://miccall.tech " style="border-bottom: none;">miccall</a></li>
            </ul>
            
                <span id="busuanzi_container_site_pv">本站总访问量<span id="busuanzi_value_site_pv"></span>次</span>
			
        </div>
    </div>
</body>



 	
</html>
